package com.taptech.doufu.ui.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.ProgressBar;

import com.taptech.doufu.util.ListViewUtil;
import com.taptech.doufu.ui.dialog.CpAddContentDialog;
import com.taptech.doufu.R;
import com.taptech.doufu.ui.activity.BrowseActivity;
import com.taptech.doufu.bean.MineAbstractBean;
import com.taptech.doufu.constant.Constant;
import com.taptech.doufu.ui.view.drawcircle.BaseRecyclerViewViewHolder;
import com.taptech.doufu.ui.view.drawcircle.MyRecyclerView;
import com.taptech.doufu.ui.view.drawcircle.MySwipeRefreshLayout;
import com.taptech.doufu.ui.view.drawcircle.RecyclerViewAdapterAsListView;
import com.taptech.doufu.listener.HttpResponseListener;
import com.taptech.doufu.ui.viewholder.personalcenter.BaseAdapterViewHolder;
import com.taptech.doufu.ui.viewholder.personalcenter.MessageViewHolderFactory;
import com.taptech.doufu.services.personalcenter.AccountService;
import com.taptech.doufu.services.personalcenter.PersonalInfoService;
import com.taptech.doufu.ui.viewholder.personalcenter.PersonalNoteViewHolder;
import com.taptech.doufu.services.CpService;
import com.taptech.doufu.services.PersonalNoteService;
import com.taptech.doufu.util.DiaobaoUtil;
import com.taptech.doufu.util.GlideUtil;
import com.taptech.doufu.util.TagsUtil;
import com.taptech.doufu.util.UIUtil;
import com.taptech.doufu.net.httputils.HttpResponseObject;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class CommonCpFragment extends ScrollAbleFragment implements HttpResponseListener, OnClickListener
{

    // UI控件
    private MyRecyclerView listView;
    private RecyclerViewAdapterAsListView adapter;
    private List<MineAbstractBean> mDataList;
    private String last = "";
    private boolean hasMoreContent = true;
    private MessageViewHolderFactory viewHolderFactory;
    private MySwipeRefreshLayout swipeRefreshLayout;
    private int current_type;
    private String key;
    public static final String ARGUMENT = "argument";
    public static final String KEY = "key";
    public static final String LOAD_LATER = "load_later";
    private int page = 0;
    private View fragment1Layout;
    public final static int TYPE_PERSONAL_NOVEL = 1001;
    public final static int TYPE_PERSONAL_DRAW = 1002;
    public static final int TYPE_SINGLE_CP_NOVEL = 1003;
    public static final int TYPE_SINGLE_CP_DRAW = 1004;
    public static final int TYPE_SINGLE_CP_SWEEP = 1005;
    public static final int TYPE_SINGLE_CP_NOTE = 1006;
    public static final int TYPE_SINGLE_TAG_DRAW = 1007;
    public static final int TYPE_SINGLE_TAG_NOVEL = 1008;
    public static final String DRAW_TYPE = Constant.OBJECT_TYPE_DRAW + "";
    private ProgressBar waitBar;
    private ImageView no_tip_view;
    private ImageView add_content_iv;
    private ImageView iv_authorpublic;
    private boolean isShowAuthorPublic = false;
    private boolean isLoadLater = false;

    public static CommonCpFragment newInstance(int type)
    {
        Bundle args = new Bundle();
        args.putInt(ARGUMENT, type);
        CommonCpFragment fragment = new CommonCpFragment();
        fragment.setArguments(args);
        return fragment;
    }

    public static CommonCpFragment newInstance(int type, String key)
    {
        Bundle args = new Bundle();
        args.putInt(ARGUMENT, type);
        args.putString(KEY, key);
        CommonCpFragment fragment = new CommonCpFragment();
        fragment.setArguments(args);
        return fragment;
    }

    public static CommonCpFragment newInstance(int type, String key, boolean loadLater)
    {
        Bundle args = new Bundle();
        args.putInt(ARGUMENT, type);
        args.putString(KEY, key);
        args.putBoolean(LOAD_LATER, loadLater);
        CommonCpFragment fragment = new CommonCpFragment();
        fragment.setArguments(args);
        return fragment;
    }



    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        Bundle bundle = getArguments();
        if (bundle != null)
        {
            current_type = bundle.getInt(ARGUMENT, 1);
            key = bundle.getString(KEY);
            isLoadLater = bundle.getBoolean(LOAD_LATER);
        }

        try
        {
            isShowAuthorPublic = bundle.getBoolean("isshowauthor");
        } catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    @Override
    public void onResume(String name, Context context)
    {
        super.onResume("CommonCpFragment", context);
    }

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        fragment1Layout = inflater.inflate(R.layout.fragment_common_layout, container, false);
        iv_authorpublic =  fragment1Layout.findViewById(R.id.iv_aboutauthor);
        initView(fragment1Layout);
        if (!isLoadLater) {
            loadData(0, "");
        }
        return fragment1Layout;
    }

    public void loadLater() {
        if (isLoadLater) {
            loadData(0,"");
            isLoadLater = false;
        }
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState)
    {
        super.onActivityCreated(savedInstanceState);

    }



    protected void initView(View parent)
    {
        add_content_iv =  parent.findViewById(R.id.add_content_iv);
        no_tip_view =  parent.findViewById(R.id.personal_draft_tip_view);
        mDataList = new ArrayList<>();
        viewHolderFactory = new MessageViewHolderFactory();
        listView = (MyRecyclerView) parent.findViewById(R.id.albums_listview);
        RecyclerView.LayoutManager manager = new LinearLayoutManager(this.getActivity());
        listView.setLayoutManager(manager);
        adapter = new RecyclerViewAdapterAsListView(this.getActivity(), mDataList, handler);
        adapter.setType(RecyclerViewAdapterAsListView.TYPE_DELETE_FROM_PERSONAL);
        listView.setAdapter(adapter);
        listView.setOnScrollToBottomListener(new MyRecyclerView.OnScrollToBottomListener()
        {
            @Override
            public void loadMore()
            {
                loadData(page, last);
            }
        });
        add_content_iv.setOnClickListener(this);
        initRefreshView();
    }

    private void initAddViewByType() {
        if (mDataList != null && mDataList.size() > 0) {
            no_tip_view.setVisibility(View.GONE);
        } else {
            no_tip_view.setVisibility(View.VISIBLE);
        }
    }

    private void initRefreshView()
    {
        waitBar = (ProgressBar) fragment1Layout.findViewById(R.id.xlistview_footer_progressbar);
        swipeRefreshLayout = (MySwipeRefreshLayout) fragment1Layout.findViewById(R.id.swipe_container);
        swipeRefreshLayout.setEnabled(false);
        swipeRefreshLayout.setSize(0);
        //刷新动画
        swipeRefreshLayout.setOnRefreshListener(new MySwipeRefreshLayout.OnRefreshListener()
        {
            @Override
            public void onRefresh()
            {
                last = "";
                loadData(0, "");
                //关闭刷新动画
                swipeRefreshLayout.setRefreshing(false);
                //关闭下拉使能已免
                swipeRefreshLayout.setEnabled(false);
                //显示顶部刷新等待窗
                waitBar.setVisibility(View.VISIBLE);
                adapter.setHeadViewVisible(View.VISIBLE);
                //将recyclerview移至顶部
                listView.smoothScrollToPosition(0);

            }
        });
        //监听recyclerview的滑动，只有recyclerview到顶部时，下拉刷新才会启动，不在顶部时下拉刷新便会关闭
        listView.setOnScrollToTopListener(new MyRecyclerView.OnScrollToTopListener()
        {
            @Override
            public void refresh()
            {
                if (!adapter.isHeadViewVisible())
                {
                    swipeRefreshLayout.setEnabled(true);
                }
            }

            @Override
            public void notAtTopInScrollView(int offsetY, int directionY)
            {
                swipeRefreshLayout.setEnabled(false);
            }

        });
    }

    @Override
    public void handleResponse(int handleType, HttpResponseObject response)
    {
        try
        {
            swipeRefreshLayout.setRefreshing(false);
            adapter.setHeadViewVisible(View.GONE);
            waitBar.setVisibility(View.GONE);
            if (response.getStatus() == Constant.STATUS_SUCCESS)
            {
                switch (handleType)
                {
                    case CpService.HANDLE_LOAD_PERSONAL_CPS_CONTENT:
                    {
                        JSONObject data = (JSONObject) response.getData();
                        List<? extends MineAbstractBean> dataList = viewHolderFactory.getDataBeanFromJSONArray(data.getJSONArray("list"));
                        if (dataList != null)
                        {
                            if (page == 0)
                            {
                                mDataList.clear();
                            }
                            mDataList.addAll(dataList);
                            if (dataList.size() < Constant.PAGE_SIZE_20)
                            {
                                adapter.pullComplete(true);
                            } else
                            {
                                page++;
                            }
                            adapter.notifyDataSetChanged();
                        }
                        break;
                    }
                    case PersonalNoteService.HANDLE_TYPE_LOAD_NOTE:
                    {
                        if (last.equals(""))
                        {
                            swipeRefreshLayout.setEnabled(true);
                        }
                        JSONObject data = (JSONObject) response.getData();
                        if (hasMoreContent)
                        {
                            List<? extends MineAbstractBean> dataList = viewHolderFactory.getDataBeanFromJSONArray(data.getJSONArray("journals"), PersonalNoteViewHolder.SPECIAL_TYPE_PERSONAL_DELETE);
                            if (dataList != null && dataList.size() > 0)
                            {
                                for (int i = 0; i < dataList.size(); i++)
                                {
                                    dataList.get(i).setSpecialType(BaseRecyclerViewViewHolder.SPECIAL_TYPE_PERSONAL_DELETE);
                                }
                                if (last.equals(""))
                                {
                                    //正常加载数据
                                    hasMoreContent = true;
                                    listView.setLoadMoreEnable(true);
                                    mDataList.clear();
                                    mDataList.addAll(dataList);
                                    adapter.notifyDataSetChanged();
                                } else if (!last.equals(data.getString("last")))
                                {
                                    hasMoreContent = true;
                                    listView.setLoadMoreEnable(true);
                                    mDataList.addAll(dataList);
                                    adapter.notifyDataSetChanged();
                                } else
                                {
                                    hasMoreContent = false;
                                    listView.setLoadMoreEnable(false);
                                    adapter.pullComplete(true);
                                }
                                last = data.getString("last");
                            } else
                            {
                                hasMoreContent = false;
                                listView.setLoadMoreEnable(false);
                                adapter.pullComplete(true);
                            }
                        }
                        break;
                    }
                    case PersonalInfoService.HANDLE_LOAD_SWEEP_MINE:
                    {
                        if (last.equals(""))
                        {
                            swipeRefreshLayout.setEnabled(true);
                        }
                        JSONObject data = (JSONObject) response.getData();
                        if (hasMoreContent)
                        {
                            List<? extends MineAbstractBean> dataList = viewHolderFactory.getDataBeanFromJSONArray(data.getJSONArray("list"), PersonalNoteViewHolder.SPECIAL_TYPE_PERSONAL_DELETE);
                            if (dataList != null && dataList.size() > 0)
                            {
                                if (last.equals(""))
                                {
                                    //正常加载数据
                                    mDataList.clear();
                                    mDataList.addAll(dataList);
                                } else
                                {
                                    mDataList.addAll(dataList);
                                }
                                if (data.getString("has_next").equals("False"))
                                {
                                    hasMoreContent = false;
                                    listView.setLoadMoreEnable(false);
                                    adapter.pullComplete(true);
                                } else
                                {
                                    hasMoreContent = true;
                                    listView.setLoadMoreEnable(true);
                                }
                                adapter.notifyDataSetChanged();
                                last = data.getString("last");
                            } else
                            {
                                hasMoreContent = false;
                                listView.setLoadMoreEnable(false);
                                adapter.pullComplete(true);
                            }
                        }
                        break;
                    }
                    case PersonalInfoService.HANDLE_LOAD_TOPIC_MINE:
                    {
                        if (last.equals(""))
                        {
                            swipeRefreshLayout.setEnabled(true);
                        }
                        JSONObject data = (JSONObject) response.getData();

                        try
                        {
                            if (data.has("signed"))
                            {
                                final JSONObject signedObject = data.getJSONObject("signed");
                                if ((isShowAuthorPublic) && (signedObject != null) && (signedObject.has("url")))
                                {
                                    iv_authorpublic.setVisibility(View.VISIBLE);
                                    if (signedObject.has("img_url"))
                                    {
                                        JSONObject imgObject = signedObject.getJSONObject("img_url");
                                        if ((imgObject.has("url")) && (imgObject.getString("url").length() > 0))
                                        {
                                            GlideUtil.displayImage(iv_authorpublic,imgObject.getString("url"));
                                        }
                                    }

                                    iv_authorpublic.setOnClickListener(new View.OnClickListener()
                                    {
                                        @Override
                                        public void onClick(View v)
                                        {
                                            try
                                            {
                                                Intent intent = new Intent(CommonCpFragment.this.getActivity(), BrowseActivity.class);
                                                intent.putExtra(Constant.URL, signedObject.getString("url"));
                                                CommonCpFragment.this.getActivity().startActivity(intent);
                                            } catch (Exception e)
                                            {
                                                e.printStackTrace();
                                            }
                                        }
                                    });
                                }
                            }
                        } catch (Exception e)
                        {
                            e.printStackTrace();
                        }

                        if (hasMoreContent)
                        {
                            List<? extends MineAbstractBean> dataList = viewHolderFactory.getDataBeanFromJSONArray(data.getJSONArray("list"), PersonalNoteViewHolder.SPECIAL_TYPE_PERSONAL_DELETE);
                            if (dataList != null && dataList.size() > 0)
                            {
                                if (last.equals(""))
                                {
                                    //正常加载数据
                                    adapter.pullComplete(true);
                                    hasMoreContent = true;
                                    listView.setLoadMoreEnable(true);
                                    mDataList.clear();
                                    mDataList.addAll(dataList);
                                    adapter.notifyDataSetChanged();
                                } else if (!last.equals(data.getString("last")))
                                {
                                    hasMoreContent = true;
                                    listView.setLoadMoreEnable(true);
                                    mDataList.addAll(dataList);
                                    adapter.notifyDataSetChanged();
                                } else
                                {
                                    hasMoreContent = false;
                                    listView.setLoadMoreEnable(false);
                                    adapter.pullComplete(true);
                                }
                                last = data.getString("last");
                            } else
                            {
                                hasMoreContent = false;
                                listView.setLoadMoreEnable(false);
                                adapter.pullComplete(true);
                            }
                        }
                        break;
                    }
                    case CpService.HANDLE_LOAD_SINGLE_CP_CONTENT:
                    {
                        if (hasMoreContent)
                        {
                            try
                            {
                                JSONObject data = (JSONObject) response.getData();
                                List<? extends MineAbstractBean> dataList = viewHolderFactory.getDataBeanFromJSONArray(data.getJSONArray("list"));
                                if (dataList != null && dataList.size() > 0)
                                {
                                    if (last.equals(""))
                                    {
                                        //正常加载数据
                                        hasMoreContent = true;
                                        listView.setLoadMoreEnable(true);
                                        mDataList.clear();
                                        mDataList.addAll(dataList);
                                        adapter.notifyDataSetChanged();
                                    } else if (!last.equals(data.getString("last")))
                                    {
                                        hasMoreContent = true;
                                        listView.setLoadMoreEnable(true);
                                        mDataList.addAll(dataList);
                                        adapter.notifyDataSetChanged();
                                    } else
                                    {
                                        hasMoreContent = false;
                                        listView.setLoadMoreEnable(false);
                                        adapter.pullComplete(true);
                                    }
                                    last = data.getString("last");
                                } else
                                {
                                    hasMoreContent = false;
                                    listView.setLoadMoreEnable(false);
                                    adapter.pullComplete(true);
                                }
                            } catch (Exception e)
                            {
                                e.printStackTrace();
                                adapter.pullComplete(true);
                            }
                        }
                        break;
                    }
                    case CpService.HANDLE_TYPE_LOAD_SINGLE_CP_JOURNALS:
                    {
                        if (last.equals(""))
                        {
                            swipeRefreshLayout.setEnabled(true);
                        }
                        JSONObject data = (JSONObject) response.getData();
                        if (hasMoreContent)
                        {
                            List<? extends MineAbstractBean> dataList = viewHolderFactory.getDataBeanFromJSONArray(data.getJSONArray("journals"));
                            if (dataList != null && dataList.size() > 0)
                            {
                                if (last.equals(""))
                                {
                                    //正常加载数据
                                    hasMoreContent = true;
                                    listView.setLoadMoreEnable(true);
                                    mDataList.clear();
                                    mDataList.addAll(dataList);
                                    adapter.notifyDataSetChanged();
                                } else if (!last.equals(data.getString("last")))
                                {
                                    hasMoreContent = true;
                                    listView.setLoadMoreEnable(true);
                                    mDataList.addAll(dataList);
                                    adapter.notifyDataSetChanged();
                                } else
                                {
                                    hasMoreContent = false;
                                    listView.setLoadMoreEnable(false);
                                    adapter.pullComplete(true);
                                }
                                last = data.getString("last");
                            } else
                            {
                                hasMoreContent = false;
                                listView.setLoadMoreEnable(false);
                                adapter.pullComplete(true);
                            }
                        }
                        break;
                    }
                    case TagsUtil.HANDLE_TYPE_TAGS2_CONTENT:
                    {
                        if (last.equals(""))
                        {
                            swipeRefreshLayout.setEnabled(true);
                        }
                        if (hasMoreContent)
                        {
                            try
                            {
                                JSONObject data = (JSONObject) response.getData();
                                List<? extends MineAbstractBean> dataList = viewHolderFactory.getDataBeanFromJSONArray(data.getJSONArray("list"));
                                if (dataList != null && dataList.size() > 0)
                                {
                                    if (last.equals(""))
                                    {
                                        //正常加载数据
                                        hasMoreContent = true;
                                        listView.setLoadMoreEnable(true);
                                        mDataList.clear();
                                        mDataList.addAll(dataList);
                                        adapter.notifyDataSetChanged();
                                    } else if (!last.equals(data.getString("last")))
                                    {
                                        hasMoreContent = true;
                                        listView.setLoadMoreEnable(true);
                                        mDataList.addAll(dataList);
                                        adapter.notifyDataSetChanged();
                                    } else
                                    {
                                        hasMoreContent = false;
                                        listView.setLoadMoreEnable(false);
                                        adapter.pullComplete(true);
                                    }
                                    last = data.getString("last");
                                } else
                                {
                                    hasMoreContent = false;
                                    listView.setLoadMoreEnable(false);
                                    adapter.pullComplete(true);
                                }
                            } catch (Exception e)
                            {
                                e.printStackTrace();
                                adapter.pullComplete(true);
                            }
                        }
                        break;
                    }
                    default:
                        break;

                }
                initAddViewByType();
            } else
            {
                UIUtil.toastMessage(getActivity(), DiaobaoUtil.getErrorTips(response));
            }
        } catch (Exception e)
        {
            e.printStackTrace();
            adapter.pullComplete(true);
            UIUtil.toastMessage(this.getActivity(), Constant.loadingFail);
        }


    }

    @Override
    public void onDestroy()
    {
        super.onDestroy();

    }

    protected synchronized void loadData(int start_page, String start_last)
    {
        page = start_page;
        last = start_last;
        switch (current_type)
        {
            case NewMyCpFragment.TYPE_CP_MY_ORDER:
                CpService.getInstance().loadPersonalCPContent(Constant.OBJECT_TYPE_SWEEP + "", page, this);
                break;
            case NewMyCpFragment.TYPE_CP_NOTE:
                if (AccountService.getInstance().isLogin())
                {
                    CpService.getInstance().loadPersonalCPContent(Constant.OBJECT_TYPE_NOTE + "", page, this);
                }
                break;
            case NewMyCpFragment.TYPE_CP_NOVEL:
                if (AccountService.getInstance().isLogin())
                {
                    CpService.getInstance().loadPersonalCPContent(Constant.OBJECT_TYPE_NOVEL + "", page, this);
                }
                break;
            case NewMyCpFragment.TYPE_CP_DRAW:
                if (AccountService.getInstance().isLogin())
                {
                    CpService.getInstance().loadPersonalCPContent(DRAW_TYPE + "", page, this);
                }
                break;
            case CommonCpFragment.TYPE_PERSONAL_NOVEL:
                PersonalInfoService.getInstance().loadPersonalTopicMine(this, last, Constant.OBJECT_TYPE_NOVEL, page, key);
                break;
            case CommonCpFragment.TYPE_PERSONAL_DRAW:
                PersonalNoteService.getInstance().loadPersoanlNoteListByUser(this, last, key, DRAW_TYPE + "");
                break;
            case NewMyCpFragment.TYPE_PERSONAL_PUBLISHED_NOTE:
                PersonalNoteService.getInstance().loadPersoanlNoteListByUser(this, last, key, Constant.OBJECT_TYPE_NOTE + "");
                break;
            case NewMyCpFragment.TYPE_PERSONAL_PUBLISHED_SWEEP:
                PersonalInfoService.getInstance().loadPersonalCenterSweepList(this, last, page, key);
                break;
            case NewMyCpFragment.TYPE_PERSONAL_PUBLISHED_UGC:
                PersonalInfoService.getInstance().loadPersonalCenterTopicList(this, last, page, key);
                break;
            case NewMyCpFragment.TYPE_PERSONAL_PUBLISHED_COS:
                PersonalNoteService.getInstance().loadPersoanlNoteListByUser(this, last, key, Constant.OBJECT_TYPE_COS + "");
                break;
            case CommonCpFragment.TYPE_SINGLE_CP_NOVEL:
                //CpService.getInstance().loadCPContent(key, last, Constant.OBJECT_TYPE_NOVEL + "", this);
                TagsUtil.getInstance().loadContentByTag2(this, key, last, Constant.OBJECT_TYPE_NOVEL + "");
                break;
            case CommonCpFragment.TYPE_SINGLE_CP_DRAW:
                TagsUtil.getInstance().loadContentByTag2(this, key, last, DRAW_TYPE + "");
                break;
            case CommonCpFragment.TYPE_SINGLE_CP_SWEEP:
                TagsUtil.getInstance().loadContentByTag2(this, key, last, Constant.OBJECT_TYPE_SWEEP + "");
                break;
            case CommonCpFragment.TYPE_SINGLE_CP_NOTE:
                CpService.getInstance().loadSingleCpJournals(key, last, this);
                break;
            case CommonCpFragment.TYPE_SINGLE_TAG_DRAW:
//                TagsUtil.getInstance().loadContentByTag2(this, key, last + "", DRAW_TYPE + "");
                break;
            case CommonCpFragment.TYPE_SINGLE_TAG_NOVEL:
                TagsUtil.getInstance().loadContentByTag2(this, key, last + "", Constant.OBJECT_TYPE_NOVEL + "");
                break;
            default:
                break;

        }
    }

    Handler handler = new Handler()
    {
        @Override
        public void handleMessage(Message msg)
        {
            final Bundle bundle = msg.getData();
            final String deleteId = bundle.getString("id");
            final int deletePositon = bundle.getInt("position");
            switch (msg.what)
            {
                // 日常
                case BaseAdapterViewHolder.DELETE_NOTE_ITEM:
                    ListViewUtil.deleteItem(getActivity(), mDataList, adapter, deletePositon, deleteId, Constant.OBJECT_TYPE_NOTE);
                    break;
                // 文评
                case BaseAdapterViewHolder.DELETE_NOVEL_REVIEW_ITEM:
                    ListViewUtil.deleteItem(getActivity(), mDataList, adapter, deletePositon, deleteId, Constant.OBJECT_TYPE_SWEEP);
                    break;
                case BaseAdapterViewHolder.DELETE_TOPIC_ITEM:
                    ListViewUtil.deleteItem(getActivity(), mDataList, adapter, deletePositon, deleteId, Constant.OBJECT_TYPE_USERS_TOPIC);
                    break;
            }
        }
    };


    private CpAddContentDialog addContentPopuWindow;

    private void makeAddContentPopupWindow()
    {
        switch (current_type)
        {
            case NewMyCpFragment.TYPE_CP_NOTE:
            case NewMyCpFragment.TYPE_CP_NOVEL:
            case NewMyCpFragment.TYPE_CP_DRAW:
                addContentPopuWindow = new CpAddContentDialog(getActivity(), R.style.UgcSweepDialog, CpAddContentDialog.TYPE_FRAGMENT);
                break;
            default:
                addContentPopuWindow = new CpAddContentDialog(getActivity(), R.style.UgcSweepDialog, CpAddContentDialog.TYPE_CPDES);
                break;

        }
        addContentPopuWindow.show();
        android.view.WindowManager.LayoutParams lp = addContentPopuWindow.getWindow().getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.MATCH_PARENT;
        addContentPopuWindow.getWindow().setAttributes(lp);
    }

    @Override
    public View getScrollableView()
    {
        return listView;
    }

    @Override
    public void onClick(View view)
    {
        if (current_type == TYPE_SINGLE_CP_DRAW)
        {
            return;
        }
        switch (view.getId())
        {
            case R.id.add_content_iv:
                makeAddContentPopupWindow();
                break;
            default:
                break;
        }
    }

    public void notifyUpdate()
    {
        last = "";
        hasMoreContent = true;
        loadData(0, "");
    }
}